# 基础镜像
FROM ubuntu:20.04

# 设置时区和避免交互提示
ENV DEBIAN_FRONTEND=noninteractive
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

# 更新包管理器并安装基础工具
RUN apt update && apt install -y \
    build-essential \
    wget \
    curl \
    git \
    && apt clean

# 安装 Nginx 所需的依赖项：PCRE 库
RUN apt update && apt install -y \
    libpcre3 \
    libpcre3-dev \
    && apt clean

# 安装 Nginx 所需的依赖项：Zlib 库
RUN apt update && apt install -y \
    zlib1g \
    zlib1g-dev \
    && apt clean

# 安装 Nginx 所需的依赖项：OpenSSL 库
RUN apt update && apt install -y \
    libssl-dev \
    && apt clean

# 下载 Nginx 源码
ARG NGINX_VERSION=1.24.0
WORKDIR /usr/src
RUN wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
    tar -xzvf nginx-${NGINX_VERSION}.tar.gz

# 克隆 nginx-rtmp-module
RUN git clone https://github.com/arut/nginx-rtmp-module.git

# 编译 Nginx 并添加 nginx-rtmp-module
WORKDIR /usr/src/nginx-${NGINX_VERSION}
RUN ./configure --prefix=/usr/local/nginx \
                --with-http_ssl_module \
                --add-module=../nginx-rtmp-module && \
    make && make install

# 创建必要目录
RUN mkdir -p /usr/local/nginx/conf/conf.d /var/log/nginx /var/tmp/nginx

# 添加默认的 Nginx 配置
COPY nginx.conf /usr/local/nginx/conf/nginx.conf

# 暴露端口
EXPOSE 1935 8000

# 启动 Nginx
CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"]
